import Mock from 'mockjs';
let Random = Mock.Random;

// 获取验证码
Mock.mock('/api/getCode', 'post', {
    "resCode": 0,
    "data": "@word(6)",
    "message": "验证码已发送"
});

// 用户注册
Mock.mock('/api/register', 'post', {
    "resCode": 0,
    "data": null,
    "message": "用户注册成功，请进行登录"
});

// 用户登录
Mock.mock('/api/login', 'post', function (data) {
    let params = JSON.parse(data.body);
    return {
        "resCode": 0,
        "data": {
            "token": Random.word(32),
            "username": params.username,
        },
        "message": "用户登录成功"
    }
});

// 新增信息
Mock.mock('/api/news/addInfo', 'post', function (data) {
    let params = JSON.parse(data.body);
    return {
        "resCode": 0,
        "data": {
            "catagoryId": params.catagoryId,
            "title": params.title,
            "content": params.content,
            "id": Random.id()
        },
        "message": "添加成功"
    }
});

// 修改信息
Mock.mock('/api/news/editInfo', 'post', function (data) {
    let params = JSON.parse(data.body);
    return {
        "resCode": 0,
        "data": {
            "catagoryId": params.catagoryId,
            "title": params.title,
            "content": params.content,
            "id": Random.id()
        },
        "message": "修改成功"
    }
});

// 获取信息
Mock.mock('/api/news/queryInfoList', 'get', {
    "resCode": 0,
    "data": {
        "data|10": [
            {
                "id": "@id()",
                "title": "@ctitle(18)",
                "content": "@csentence(50)",
                "categoryId|1": ["1", "2", "3", "4"],
                "createDate": "@date('T')",
            },
        ],
        "total": 20
    },
    "message": "查询成功"
});

// 删除信息
Mock.mock('/api/news/deleteInfo', 'post', {
    "resCode": 0,
    "data": null,
    "message": "删除成功"
});

// 添加一级分类
Mock.mock('/api/news/addFirstCategory', 'post', function (data) {
    let params = JSON.parse(data.body);
    return {
        "resCode": 0,
        "data": {
            "categoryName": params.categoryName,
            "id": Random.word(11)
        },
        "message": "添加成功"
    }
});

// 修改一级分类
Mock.mock('/api/news/editCategory', 'post', function (data) {
    let params = JSON.parse(data.body);
    return {
        "resCode": 0,
        "data": {
            "categoryName": params.categoryName,
            "id": params.id
        },
        "message": "修改成功"
    }
});

// 添加子级分类
Mock.mock('/api/news/addChildrenCategory', 'post', function (data) {
    let params = JSON.parse(data.body);
    return {
        "resCode": 0,
        "data": {
            "categoryName": params.categoryName,
            "id": Random.word(11)
        },
        "message": "添加成功"
    }
});

// 获取分类
Mock.mock('/api/news/queryCategoryList', 'get', {
    "resCode": 0,
    "data": [
        {
            "id": "1",
            "categoryName": "国内信息",
            "children": [
                {
                    "id": "11",
                    "categoryName": "国内信息",
                },
            ],
        },
        {
            "id": "2",
            "categoryName": "国际信息",
            "children": [
                {
                    "id": "21",
                    "categoryName": "国际信息",
                },
            ],
        },
        {
            "id": "3",
            "categoryName": "劲爆消息",
            "children": [
                {
                    "id": "31",
                    "categoryName": "劲爆消息",
                },
            ],
        },
        {
            "id": "4",
            "categoryName": "热点新闻",
            "children": [
                {
                    "id": "41",
                    "categoryName": "热点新闻",
                },
            ],
        },
    ],
    "message": "查询成功"
});

// 删除分类
Mock.mock('/api/news/deleteCategory', 'post', {
    "resCode": 0,
    "data": null,
    "message": "删除成功"
});
